<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>    
    <div id="app">       
        <book  :name="name" :author="str" @click="fn"></book>
    </div>

    <script src="./js/vue.global.js"></script>

    <script>

        let book = {
            props:['name','author'],
            // emits:['click'],
            emits:{
                // 这种写法，限定了，触发事件是，传给事件处理函数的参数必须是number类型。
                click(n){
                    console.log("n",n);
                    // 要求传参参数n是number类型
                    if(typeof n == "number"){
                        return true;
                    }else{
                        // 主动抛出一个异常，异常类型是TypeError
                        throw new TypeError("传参的参数类型应该是number类型");
                        return false;
                    }
                }
            },
            template:`
                <div>书籍组件</div>
                <p>书名:{{name}}</p>
                <p @mouseover="overHandle">作者:{{author}}</p>   
            `,
            methods:{
                overHandle(){
                    this.$emit("click",222);
                }
            }
        }

       
        let app = Vue.createApp({
            data(){
                return {
                    msg:"hello",
                    name:"三国演义",
                    str:"罗贯中"
                }
            },
            methods:{
                fn(str){
                    console.log("str",str);                    
                }
            }            
        });

        app.component("book",book);
      
        app.mount("#app");

    </script>
</body>
</html>